function squirrel
  close all
  m = 0.075; cD = 0.00247; cL = 0.0084; g=9.81;
  tspan = [0,5];
  initial_w = [0,10,5.4,0];
  
  options = odeset('Event',@(t,w) event_function(t,w,m,cD,cL,g))
  [t_vals,sol_vals] = ode45(@(t,w) eom(t,w,m,cD,cL,g),tspan,initial_w,options);
  plot(sol_vals(:,1),sol_vals(:,2),'Linewidth',2,'Color','r');
  set(gca,'FontSize',14);
  xlabel('x (m)');
  ylabel('y (m)');
  title('Squirrel Trajectory');
  grid on
end
function dwdt = eom(t,w,m,cD,cL,g)
   x = w(1); y = w(2); vx = w(3); vy = w(4);
   dxdt = vx;
   dydt = vy;
   V = sqrt(vx^2 + vy^2);
   dvxdt = -cD*V*vx/m - cL*V*vy/m;
   dvydt = -cD*V*vy/m + cL*V*vx/m - g;   
   dwdt = [dxdt;dydt;dvxdt;dvydt];
end
function [e_val,stop_flag,event_dir] = event_function(t,w,m,cD,cL,g)
   x = w(1); y = w(2); vx = w(3); vy = w(4);
   e_val = y;
   stop_flag = 1;
   event_dir = -1;
end
